Is the problem in the below code related to memory allocation for array of pointers